package edu.fiu.cis.personalize.server.graph.store;

import java.util.HashMap;
import java.util.Set;

import edu.fiu.cis.personalize.server.graph.Document;
import edu.fiu.cis.personalize.server.graph.Group;
import edu.fiu.cis.personalize.server.graph.Node;
import edu.fiu.cis.personalize.server.graph.NodeType;
import edu.fiu.cis.personalize.server.graph.Query;
import edu.fiu.cis.personalize.server.graph.User;

public class NodeEdges {

	private int nodeId;

	private HashMap<NodeType, Edges<? extends Node>> edges = new HashMap<NodeType, Edges<? extends Node>>();

	public NodeEdges(int nodeId) {
		super();
		this.nodeId = nodeId;
		edges.put(NodeType.DOCUMENT, new Edges<Document>());
		edges.put(NodeType.QUERY, new Edges<Query>());
		edges.put(NodeType.USER, new Edges<User>());
		edges.put(NodeType.GROUP, new Edges<Group>());
	}

	public void setInLink(Node n, double w) {
		edges.get(n.getType()).addInLink(n, w);
	}

	public void setOutLink(Node n, double w) {
		edges.get(n.getType()).addOutLink(n, w);
	}

	public int getInDegree(NodeType type) {
		return getInLinkIds(type).size();
	}

	public int getOutDegree(NodeType type) {
		return getOutLinkIds(type).size();
	}

	public Set<Integer> getInLinkIds(NodeType type) {
		return edges.get(type).getInLinkIds();
	}

	public Set<Integer> getOutLinkIds(NodeType type) {
		return edges.get(type).getOutLinkIds();
	}

	public double getOutLinkWeight(Node n) {
		return edges.get(n.getType()).getOutLinkWeight(n);
	}

	public double getInLinkWeight(Node n) {
		return edges.get(n.getType()).getInLinkWeight(n);
	}

	public int getNodeId() {
		return nodeId;
	}

	public Edges<? extends Node> getEdgeMap(NodeType user) {
		return edges.get(user);
	}

	public static NodeEdges load(int id, Edges<Node> user, Edges<Node> doc,
			Edges<Node> group, Edges<Node> query) {
		NodeEdges ne = new NodeEdges(id);
		ne.edges.put(NodeType.DOCUMENT, doc);
		ne.edges.put(NodeType.USER, user);
		ne.edges.put(NodeType.GROUP, group);
		ne.edges.put(NodeType.QUERY, query);
		return ne;
	}
}
